!!!
%html
  %body
    .span15
      .container
        .col-md-12
          .row
            .page-header
              %h1
                Agents
            .row
              .col-md-10.pull-left
                Agents are remote workers that process distributed hashcat jobs.
              .col-md-2.pull-right
                .well.well-sm
                  - agents_online = 0
                  - total_gpus = 0
                  - total_cpus = 0
                  - total_speed = 0
                  - speed = 0
                  - @agents.each do |agent|
                    - if agent.status == 'Online' || agent.status == 'Working' || agent.status == 'Idle'
                      - agents_online += 1
                      - if agent.gpu_count
                        - total_gpus += agent.gpu_count.to_i
                      - if agent.cpu_count
                        - total_cpus += agent.cpu_count.to_i
                      - if agent.benchmark
                        - if agent.benchmark.include? 'kH/s'
                          - speed = agent.benchmark.split()[0].to_f
                          - speed = speed * 1000
                          - total_speed += speed
                        - if agent.benchmark.include? 'MH/s'
                          - speed = agent.benchmark.split()[0].to_f
                          - speed = speed * 1000000
                          - total_speed += speed
                        - if agent.benchmark.include? 'GH/s'
                          - speed = agent.benchmark.split()[0].to_f
                          - speed = speed * 1000000000
                          - total_speed += speed
                        - if agent.benchmark.include? 'TH/s'
                          - speed = agent.benchmark.split()[0].to_f
                          - speed = speed * 1000000000000
                          - total_speed += speed
                  Agents online
                  .badge #{agents_online}
                  .p
                  GPUs total
                  .badge #{total_gpus}
                  .p
                  CPUs total
                  .badge #{total_cpus}
                  .p
                  Total Speed:
                  .p
                  <b>
                  - speed_count = total_speed.to_i.to_s.size
                  - if speed_count > 12
                    - total_speed = total_speed / 1000000000000
                    #{total_speed.round} TH/s
                  - elsif speed_count > 9
                    - total_speed = total_speed / 1000000000
                    #{total_speed.round} GH/s
                  - elsif speed_count > 6
                    - total_speed = total_speed / 1000000
                    #{total_speed.round} MH/s
                  - elsif speed_count > 3
                    - total_speed = total_speed / 1000000
                    #{total_speed.round} kH/s
                  </b>
      %br
      %br
      .container
        .row
          .col-md-12
            .table
              %table{id: 'agenttable', class: 'table table-striped'}
                %thead
                  %tr
                    %th
                      %b Agent Name
                    %th
                      %b Status
                    %th
                      %b IP
                    %th
                      %b Speed
                    %th
                      %b Last Heartbeat
                    %th
                      %b Controls
                %tbody
                  - if @agents
                    - @agents.each do |agent|
                      - link = rand(36**8).to_s(36)
                      %tr
                        %td{class: 'accordian-toggle', "data-toggle" => 'collapse', href: "#collapse-#{link}"} #{agent.name}
                        %td{class: 'accordian-toggle', "data-toggle" => 'collapse', href: "#collapse-#{link}"} #{agent.status}
                        %td{class: 'accordian-toggle', "data-toggle" => 'collapse', href: "#collapse-#{link}"} #{agent.src_ip}
                        %td{class: 'accordian-toggle', "data-toggle" => 'collapse', href: "#collapse-#{link}"} #{agent.benchmark}
                        %td{class: 'accordian-toggle', "data-toggle" => 'collapse', href: "#collapse-#{link}"} #{agent.heartbeat}
                        %td
                          - if agent.src_ip == '127.0.0.1' || agent.src_ip == 'localhost'
                            - if agent.status == 'Authorized' || agent.status == 'Online' || agent.status == 'Offline' || agent.status == 'Working' || agent.status == 'Idle'
                              %a.btn.btn-primary.disabled{href: "/agents/#{agent.id}/deauthorize"}
                                Deauthorize
                            - else
                              %a.btn.btn-primary{href: "/agents/#{agent.id}/authorize"}
                                Authorize
                            %a.btn.btn-warning{href: "/agents/#{agent.id}/edit"}
                              %i.glyphicon.glyphicon-cog{title: 'Edit'}
                            %a.btn.btn-danger.disabled{href: "/agents/#{agent.id}/delete"}
                              %i.glyphicon.glyphicon-trash{title: 'Delete'}
                          - else
                            - if agent.status == 'Pending'
                              %a.btn.btn-primary{href: "/agents/#{agent.id}/authorize"}
                                Authorize
                            - else
                              %a.btn.btn-primary{href: "/agents/#{agent.id}/deauthorize"}
                                Deauthorize
                            %a.btn.btn-warning{href: "/agents/#{agent.id}/edit"}
                              %i.glyphicon.glyphicon-cog{title: 'Edit'}
                            %a.btn.btn-danger{href: "/agents/#{agent.id}/delete"}
                              %i.glyphicon.glyphicon-trash{title: 'Delete'}
                      - if agent.hc_status
                        - unless agent.hc_status.empty?
                          %tr
                            %td{colspan: 6}
                              %div{id: "collapse-#{link}", class: "panel-collapse collapse in"}
                                %h4 Hashcat Status
                                %br
                                %table{class: 'table'}
                                  - unless agent.hc_status.empty?
                                    - JSON.parse(agent.hc_status).each do |k,v|
                                      %tr
                                        %td.col-md-4
                                          #{k}
                                        %td
                                          #{v}

